package de.sky.mathparser;

import java.text.ParseException;
import java.util.List;

import de.sky.mathparser.parser.Expression;
import de.sky.mathparser.parser.lexer.Lexer;
import de.sky.mathparser.parser.parser.Parser;
import de.sky.mathparser.parser.syntaxtree.AbstractSyntaxTree;
import de.sky.mathparser.parser.token.Token;

public class Main {

	public static void main(String[] args) throws ParseException {
		String[] lines = { "(((1+2+3)*1)/1)" };

		for (String line : lines) {
			Lexer l = new Lexer();
			List<Token> tokens = l.lex(line);

			System.out.println("Tokens: " + tokens.toString());

			Parser p = new Parser();
			AbstractSyntaxTree ast = p.parse(tokens);

			Expression ex = new Expression();
			double result = ex.evaluate(ast);

			System.out.println(line);
			System.out.println(" -> ");
			System.out.println(result);
		}
	}

}
